/***
 * @Description: 本文件是协议栈定义外部接口调用函数的头文件
 * @Author: Liverpool
 * @Date: 2024-09-05 00:29:10
 * @LastEditTime: 2024-09-05 00:29:44
 * @LastEditors: Liverpool
 */
#ifndef NET_API_H
#define NET_API_H

#include "tools.h"
#include "socket.h"

// 大小端转换函数定义,宏定义
#undef htons
#define htons(x) x_htons(x)
#undef htonl
#define htonl(x) x_htonl(x)
#undef ntohs
#define ntohs(x) x_ntohs(x)
#undef ntohl
#define ntohl(x) x_ntohl(x)

// 地址转换函数定义
char *x_inet_ntoa(struct x_in_addr in);                                             // ip地址->字符串
uint32_t x_inet_addr(const char *str);                                              // 字符串->ip地址
const char *x_inet_ntop(int family, const void *addrptr, char *strptr, size_t len); // ip地址->字符串
int x_inet_pton(int family, const char *strptr, void *addrptr);                     // 字符串->ip地址

// 地址转换函数定义,宏定义
#define inet_ntoa(in) x_inet_ntoa(in)
#define inet_addr(str) x_inet_addr(str)
#define inet_ntop(family, addrptr, strptr, len) x_inet_ntop(family, addrptr, strptr, len)
#define inet_pton(family, strptr, addrptr) x_inet_pton(family, strptr, addrptr)

#define sockaddr_in x_sockaddr_in
#define sockaddr x_sockaddr
#define socklen_t x_socklen_t
#define timeval x_timeval

#define socket(family, type, protocol) x_socket(family, type, protocol)
#define sendto(s, buf, len, flags, dest, dlen) x_sendto(s, buf, len, flags, dest, dlen)
#define recvfrom(s, buf, len, flags, src, slen) x_recvfrom(s, buf, len, flags, src, slen)
#define setsockopt(s, level, optname, optval, len) x_setsockopt(s, level, optname, optval, len)

#endif // ! NET_API_H